package ASE;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JLabel;
import java.util.List;

public class GUI extends JFrame {

	//Class Declarations
	JLabel RefrenuceLable , nameLabel ;
	JTextField  RefrunceTextField ,nameTextField , UnckeckedTextField ;
	JButton submitbutton ;
	int unckecked ;
	List<Booking>BookingList ;
	
	//TextHandler handler = null;
	//Constructor
	public GUI( List<Booking>BookingList , int unckecked) {
		this.unckecked = unckecked;
		this.BookingList =BookingList ; 
		
		Container container = getContentPane();
		
		container.setLayout(new FlowLayout());
		RefrenuceLable = new JLabel("Refrunce");
		nameLabel = new JLabel("name");
		RefrunceTextField = new JTextField(10);
		nameTextField =new JTextField(10);
		UnckeckedTextField = new JTextField(20);
		submitbutton = new JButton("Submit");
		
		UnckeckedTextField.setEditable(false);
		
		UnckeckedTextField.setText("still Unckeckd in "+Integer.toString(unckecked)+" Passengers");   
		
    	container.add(RefrenuceLable);
		container.add(RefrunceTextField);
		container.add(nameLabel);
		container.add(nameTextField);
		container.add(submitbutton);
		container.add(UnckeckedTextField);
		setSize(500, 300);
		setVisible(true);
	
	

		submitbutton.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
		    String Ref , name ;
			Ref = RefrunceTextField.getText().trim();
			RefrunceTextField.setText("");
			name = nameTextField.getText().trim();
			nameTextField.setText("");
			getIndex(Ref , name  );
}});
	}
	  public void getIndex( String ref , String name  )
	    {   
		  ref = ref.trim();
		  name =name.trim();
		//  System.out.println(unckecked + "GUI");
	    	for(int x=0 ; x< this.BookingList.size() ;x++)
	    	{
	    		if (this.BookingList.get(x).Ref.contentEquals(ref)&& this.BookingList.get(x).passenger.name.contentEquals(name) )
	    		{
	    			this.BookingList.get(x).checked_In = "yes";
	    			 -- (this.unckecked) ;
	    			 UnckeckedTextField.setText("still Unckeckd in "+Integer.toString(this.unckecked)+" Passengers");  
	    		} 
	    		
	    	}
	    	if (this.unckecked==0)
	    		setVisible(false);
	    	
	    }
	/*  public boolean checkRefrunce(String ref)
	  {   
	     
		 // if (ref > 00000 && ref <=00999)
			//  return true ;
		   //   return false ;
		  
	  }*/
	  
}// End of class TextFieldTest